package org.clockworkmages.games.anno1186.dao;

import java.awt.Image;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileUtil {

	public static Image getResourceAsImage(String resourcePath) {
		try {
			Image image = javax.imageio.ImageIO.read(FileUtil.class
					.getClassLoader().getResourceAsStream(resourcePath));
			return image;
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}

	public static void write(String filePath, String content) {
		File file = new File(filePath);
		try {
			// if file doesn't exists, then create it
			if (!file.exists()) {
				file.createNewFile();
			}

			FileOutputStream fop = new FileOutputStream(file);

			// get the content in bytes
			byte[] contentInBytes = content.getBytes();

			fop.write(contentInBytes);
			fop.flush();
			fop.close();

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
